/**
 * 
 */
package com.ttl.bc.report.p1;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

 
import com.ttl.common.user.department.ITTL_UserDepartment;
import com.ttl.common.util.CommonUtils;

/**
 *  @author :  Surasak Lekmart
 *  Created :  13 Nov 2012 11:25:33 
 *  Project :  ittl
 */
public class P1Action extends DispatchAction {

	public ActionForward blank(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
		
		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.print(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :P1Action #mode :blank ");		

		
		return mapping.findForward("blank");
	}	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ActionForward print_bcstkissue2sub(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
		
		 
		
		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.print(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :P1Action #mode :print ");		
		List<ITTL_UserDepartment> udList = (List<ITTL_UserDepartment>)request.getSession().getAttribute("userInDepartmentList"); 
		
		String creatorCode = "'',";
		if(udList!=null && udList.size()>0) {
			for (ITTL_UserDepartment ud : udList) {
				creatorCode = creatorCode + "'"+ud.getUserInDepartment()+"',";
			}
			creatorCode = creatorCode.substring(0, creatorCode.length()-1);
		}
		System.out.println("creatorCode = "+creatorCode);
			
		String nameOfReport = "/ireport/bcstkissue2sub.jasper";			
							
		HashMap hashMap = new HashMap();
		hashMap.put("creatorCode", creatorCode);

		if(CommonUtils.runReportToPdf(response, getServlet(), hashMap, nameOfReport)==true) {
			 
			System.out.println("run report to pdf: complete");
		}else {
			System.out.println("run Report to pdf: can't run report");
		}
		
		return null;
	}
}
